import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
import { listDataGroupTree } from '/@/api/infra/dataGroup';
import { DataGroupBizType } from "/@/components/BizDataGroup/index"
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types'
const { t } = useI18n('');

export const columns: BasicColumn[] = [
  {
    title: t('表单名'),
    dataIndex: 'name',
    width: 100,
  },
  {
    title: t('表名称'),
    dataIndex: 'tableName',
    width: 100,
  },
  // {
  //   title: t('数据源'),
  //   dataIndex: 'datasourceName',
  //   width: 100,
  // },
  {
    title: t('所属组'),
    dataIndex: 'groupName',
    width: 100,
  },
 
  {
    title: t('创建时间'),
    dataIndex: 'updatedAt',
    width: 150,
    align: 'center',
  },
  {
    title: t('备注'),
    dataIndex: 'remark',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('表单名'),
    field: 'name',
    component: 'Input',
  },
];



export const inputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: t('表单名'),
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: t('表名称'),
    field: 'tableName',
    component: 'Input',
    required: true,
    componentProps: {
      maxlength: 300,
    },

  },
  {
    field: 'datasourceId',
    label: '数据源',
    component: 'Select',
    required: false,
    componentProps: () => {
      return {
        options: []
      };
    },
  },
  {
    label: '所属组',
    field: 'groupId',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: listDataGroupTree,
      params: {
        bizType: DataGroupBizType.DIY_FORM,
      },
      optionFilterProp: "label",
      showSearch: true,
      labelField: 'name',
      valueField: 'id',
      dropdownStyle: { maxHeight: '16vh', overflow: 'auto' },
    }
  },
  {
    label: t('备注信息'),
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
      autoSize: {
        minRows: 5,
        maxRows: 10
      }
    },
    colProps: { lg: 24, md: 24 },
  },
];


export const formDetailSchema: DescItem[] = [
  {
    label: t('表单名'),
    field: 'name'
  },
  {
    label: t('表名'),
    field: 'tableName'
  },
  {
    label: t('数据源'),
    field: 'datasourceName'
  },
  {
    label: t('所属组'),
    field: 'groupName'
  },
  {
    label: t('创建者'),
    field: 'createdBy'
  },
  {
    label: t('创建时间'),
    field: 'createdAt'
  },
  {
    label: t('更新者'),
    field: 'updatedBy'
  },
  {
    label: t('更新时间'),
    field: 'updatedAt'
  },
  {
    label: t('备注'),
    labelMinWidth: 40,
    field: 'remark',
  },
];


  /**
   * 字段
   */
  export const fieldColumns : JVxeColumn[] = [
    // 表的列id
    { title: 'ID', key: 'id', type: JVxeTypes.hidden },
    { 
      title: '字段名称', key: 'columnName', type: JVxeTypes.input, width: 200, defaultValue: 'not value',
      validateRules: [{ required: true, message: '${title}不能为空' }],
    },
    { 
      title: '字段描述', key: 'columnComment', type: JVxeTypes.input, width: 220, defaultValue: '' 
    },
    { 
      title: '属性名', key: 'attrName', type: JVxeTypes.input, width: 220, defaultValue: '' 
    },
    { 
      title: '插入',key: 'isInsert', type: JVxeTypes.checkbox, width: 80,
      customValue: [true, false], defaultChecked: false,
    },
    {
      title: '编辑', key: 'isEdit', type: JVxeTypes.checkbox, width: 80,
      customValue: [true, false], defaultChecked: false,
    },
    {
      title: '列表', key: 'isList', type: JVxeTypes.checkbox, width: 80,
      customValue: [true, false], defaultChecked: false,
    },
    { 
      title: '详情', key: 'isDetail', type: JVxeTypes.checkbox, width: 80, 
      customValue: [true, false], defaultChecked: false,
    },
    { 
      title: '查询', key: 'isQuery', type: JVxeTypes.checkbox, width: 80, 
      customValue: [true, false], defaultChecked: false,
    },
    {
      title: '查询方式', key: 'queryType', type: JVxeTypes.select, width: 140,
      options: [], dictCode: 'query_type', placeholder: '请选择',
    },
    {
      title: '显示类型', key: 'htmlType', type: JVxeTypes.select, width: 140, defaultValue: 'input',
      options: [], dictCode: 'lcp_ui_compoent', placeholder: '请选择',
    },
    {
      title: '字典类型', key: 'dictType', type: JVxeTypes.selectDictSearch, 
      minWidth: 200, placeholder: '请输入',
      props: {}
    }
  ]